<script>
var AdminAside = {
    data: {
        asideData: {},
        asideDefaultOpenKeys: [],
    },
    methods: {
        countAsideProjects(awardId, statusIds, largeGroupId = null) {
            if (!this.asideData.project_stats) {
                return 0
            }
            var result = 0;
            this.asideData.project_stats.forEach(item => {
                if (item.award_id == awardId) {
                    if (statusIds.includes(item.status_id)) {
                        if (largeGroupId !== null) {
                            if (largeGroupId == item.large_group_id) {
                                result += item.count
                            }
                        } else {
                            result += item.count
                        }
                    }
                }
            });
            return result
        },
        countAsideProjects1(awardId, statusIds, profCategories) {
            if (!this.asideData.project_stats) {
                return 0
            }
            var result = 0;
            this.asideData.project_stats.forEach(item => {
                if (item.award_id == awardId) {
                    if (statusIds.includes(item.status_id)) {
                        if (profCategories) {
                            if (profCategories.includes(item.prof_category)) {
                                result += item.count
                            }
                        } else {
                            result += item.count
                        }
                    }
                }
            });
            return result
        },
        reloadAsideData() {
            axios.get('/api/admin/get-aside-data')
                .then(response => {
                    this.asideData = response.data
                })
        },
        loadAsideDefaultOpenKeys() {
            console.log('enter loadAsideDefaultOpenKeys');
            try {
                var defaultOpenKeys = JSON.parse(localStorage['adminAsideDefaultOpenKeys']);
                if (Array.isArray(defaultOpenKeys)) {
                    this.asideDefaultOpenKeys = defaultOpenKeys
                }
            } catch(e) {
            }
        },
        handleAsideOpenChange(openKeys) {
            console.log('enter handleAsideOpenChange-'+openKeys);
            localStorage['adminAsideDefaultOpenKeys'] = JSON.stringify(openKeys)
        },
    },
}
</script>